﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using YAPL.Language.Ast;
using YAPL.Util;
namespace YAPL.Language.SourceParser.XML.NodeParsers {
	public class XmlClassDefParser : XmlExpressionParser {
		public XmlClassDefParser(XmlInputParser parser) : base(parser) {}
		public override Expression ParseNode(XElement node) {

			var name = node.Attribute(XmlNames.ClassNameAttribute);
			Require.NotNull(name);
			Require.NotEmpty(name.Value);

			//parse class body
			var bodyElement = node.Element(XmlNames.CodeBlockExpression);
			Require.NotNull(bodyElement);
			var classBody = (CodeBlockExpression)Parser.ParseNode(bodyElement);

			return Expressions.ClassDef(name.Value, classBody);
		}
	}
}
